(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:TongjiCtrl
     * @description
     * # TongjiCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('TongjiCtrl', TongjiCtrl);

    TongjiCtrl.$inject = ['$scope', 'dataService', '$state', 'helper', '$location', '$rootScope', '$timeout', 'moment'];

    function TongjiCtrl($scope, dataService, $state, helper, $location, $rootScope, $timeout, moment) {

        $scope.listAction = function() {
            $scope.pageSize = 10;
            $scope.chosedType = 'payment';
            $scope.getlist();
        }
        
        //查询活动列表
        $scope.getlist = function(pageNo) {
            $scope.pageNo = pageNo ? pageNo : 1;
            var query = {
                page_no: $scope.pageNo,
                page_size: $scope.pageSize,
                type:$scope.chosedType
            };
            dataService.tongjiGet(query).then(function(r) {
                if (r.data) {
                    $scope.paymentlist = r.data;
                    $scope.total_count = r.count;
                }
            })
        }

       
        $scope.addAction = function() {
            // $scope.savedakaData();
            $scope.ting_class_id = $location.search().ting_class_id;
            if ($scope.ting_class_id) {
                dataService.tingClassDetailGet($scope.ting_class_id).then(function(r) {
                    if (r) {
                       $scope.classDetail = r.class_list;
                    }
                })
            } 
        }

        $scope.infoAction = function() {
            $scope.gift_id = $location.search().gift_id;
            $scope.type = $location.search().type;
            if ($scope.gift_id) {
                $scope.getGiftInfoList();
            }
        }
        $scope.getGiftInfoList = function(pageNo) {
                var data = {
                    content: {
                        page_no: pageNo ? pageNo : "1",
                        page_size: $scope.page_Size,
                        gift_id: $scope.gift_id,
                        store_id: $rootScope.store_id,
                        start_time: $scope.start_time,
                        end_time: $scope.end_time,
                    }
                }
                dataService.giftdetailsGet(data).then(function(r) {
                    if (!r.Msg) {
                        $timeout(function() {
                            $scope.giftdetails = r.details_list;
                            $scope.total_count = r.total_count;
                            $scope.baobiao();
                        });
                    } else {
                        helper.myAlert("error:" + r.Msg);
                    }
                });
            }
            //数据报表
        $scope.baobiao = function() {
                // console.error(moment().format('YYYY-MM-DD 00:00:00'));
                dataService.giftBaobiao($scope.gift_id, moment().format('YYYY-MM-DD 00:00:00')).then(function(r) {
                    if (r) {
                        $scope.giftnums = r;
                    }
                })
            }
            //核销礼物
        $scope.destroy = function(gift_d_id) {
            helper.myConfirm("确认领取礼物吗？", function() {
                dataService.giftDestroy(gift_d_id).then(function(r) {
                    if (r.gift_d_id) {
                        helper.myAlert("领取成功！");
                        $scope.getGiftInfoList();
                    } else {
                        helper.myAlert(r.Msg);
                    }
                })
            });

        }

        $scope.saveData = function() {
            var data = {
                content: {
                    gift_id: $scope.gift.gift_id,
                    store_id: $rootScope.store_id,
                    name: $scope.gift.name,
                    type: $scope.gift.type,
                    effective: $scope.gift.effective,
                    desc: $scope.gift.desc
                }
            };

            dataService.giftAdd(data).then(function(r) {
                if (!r || r.Msg) {
                    helper.myAlert("error:" + r.Msg);
                } else {
                    helper.myAlert("success", null, null, function() {
                        $state.go("gifts.list");
                    });
                }
            })
        }
        $scope.savedakaData = function() {
            // console.error($scope.gift);return;
            var data = {
                content: {
                    gift_id: $scope.gift.gift_id,
                    // xid: "12124afafdasfdsafsafsa",
                    // store_id: $rootScope.store_id,
                    // member_id:'17080319',
                    // type: 1,
                    // phone:"15169893332",
                }
            };

            dataService.dakaAdd(data).then(function(r) {

            })
        }
        $scope.setDesc = function(type) {
            if (type == 2) {
                $scope.gift.desc = {
                    "answerItems": {
                        "A1": {
                            "name": "伪球迷",
                            "content": "",
                            "img": "https://img.dhfapp.com/static/uploads/a1006e70-57ab-41cc-8d01-32160dbd4120.jpg",
                            "titleColor": "#011132"
                        },
                        "A2": {
                            "name": "墙头草",
                            "content": "",
                            "img": "https://img.dhfapp.com/static/uploads/09e85ff6-f1f9-49ff-8349-7808d50b22c4.jpg",
                            "titleColor": "#011132"
                        },
                        "A3": {
                            "name": "中级球迷",
                            "content": "",
                            "img": "https://img.dhfapp.com/static/uploads/5d42dc9f-1374-49f3-be2b-2d6351d0e689.jpg",
                            "titleColor": "#011132"
                        },
                        "A4": {
                            "name": "铁杆球迷",
                            "content": "",
                            "img": "https://img.dhfapp.com/static/uploads/086daf17-95f2-4b18-be54-ad67c9f470c8.jpg",
                            "titleColor": "#011132"
                        },
                        "A5": {
                            "name": "专业球迷",
                            "content": "",
                            "img": "https://img.dhfapp.com/static/uploads/47ac429a-e7ce-4181-bb91-c2da5b5edef4.jpg",
                            "titleColor": "#011132"
                        },
                        "A6": {
                            "name": "骨灰级球迷",
                            "content": "",
                            "img": "https://img.dhfapp.com/static/uploads/78c02b43-3f48-40fd-8494-fcf492f40a83.jpg",
                            "titleColor": "#011132"
                        },
                        "A7": {
                            "name": "不要老婆球迷",
                            "content": "",
                            "img": "https://img.dhfapp.com/static/uploads/dd7a21db-fdec-420c-a24f-21662bc6df90.jpg",
                            "titleColor": "#011132"
                        }
                    },
                    "topic": [{
                        "id": 1,
                        "problem": "下面哪一只球队参加了此次世界杯",
                        "answerItem": [{
                                "showValue": "意大利队",
                                "showId": "A:",
                                "q_id": 3
                            },
                            {
                                "showValue": "巴拿马队",
                                "showId": "B:",
                                "q_id": 2
                            },
                            {
                                "showValue": "荷兰队",
                                "showId": "C:",
                                "q_id": 3
                            }
                        ]
                    }, {
                        "id": 2,
                        "problem": "下面哪个球星未参加本次世界杯",
                        "answerItem": [{
                                "showValue": "布冯",
                                "showId": "A:",
                                "q_id": 4
                            },
                            {
                                "showValue": "保利尼奥",
                                "showId": "B:",
                                "q_id": 5
                            }, {
                                "showValue": "萨内",
                                "showId": "C:",
                                "q_id": 4
                            }
                        ]
                    }, {
                        "id": 3,
                        "problem": "世界杯总共有多少场比赛",
                        "answerItem": [{
                                "showValue": "63",
                                "showId": "A:",
                                "q_id": 5
                            },
                            {
                                "showValue": "64",
                                "showId": "B:",
                                "q_id": 4
                            }, {
                                "showValue": "62",
                                "showId": "C:",
                                "q_id": 5
                            }
                        ]
                    }, {
                        "id": 4,
                        "problem": "本次俄罗斯世界杯的吉祥物是",
                        "answerItem": [{
                            "showValue": "哈士奇",
                            "showId": "A:",
                            "q_id": 7
                        }, {
                            "showValue": "一匹狼",
                            "showId": "B:",
                            "q_id": 6
                        }, {
                            "showValue": "萨摩耶",
                            "showId": "C:",
                            "q_id": 7
                        }]
                    }, {
                        "id": 5,
                        "problem": "请排列梅西、C罗、内马尔此次杯赛所在的队伍",
                        "answerItem": [{
                            "showValue": "阿根廷、巴西、乌拉圭",
                            "showId": "A:",
                            "q_id": 7
                        }, {
                            "showValue": "巴萨、皇马、巴黎",
                            "showId": "B:",
                            "q_id": 7
                        }, {
                            "showValue": "阿根廷、葡萄牙、巴西",
                            "showId": "C:",
                            "q_id": 6
                        }]
                    }, {
                        "id": 6,
                        "problem": "下面哪一款APP看球最方便",
                        "answerItem": [{
                            "showValue": "乐视APP",
                            "showId": "A:",
                            "q_id": 9
                        }, {
                            "showValue": "360直播",
                            "showId": "B:",
                            "q_id": 8
                        }, {
                            "showValue": "爱奇艺",
                            "showId": "C:",
                            "q_id": 10
                        }]
                    }, {
                        "id": 7,
                        "problem": "梅西、C罗、诺伊尔在足球场比赛上主要用各自身体的哪个部位？",
                        "answerItem": [{
                            "showValue": "左脚、右脚、左脚",
                            "showId": "A:",
                            "q_id": 10
                        }, {
                            "showValue": "左脚、右脚、右脚",
                            "showId": "B:",
                            "q_id": 9
                        }, {
                            "showValue": "左脚、右脚、双手",
                            "showId": "C:",
                            "q_id": 8
                        }]
                    }, {
                        "id": 8,
                        "problem": "对于“主让一球球半”下面解释正确的是",
                        "answerItem": [{
                            "showValue": "如果主队3-1胜出，则主队赢盘",
                            "showId": "A:",
                            "results": { "女": "A7", "男": "A6" }
                        }, {
                            "showValue": "如果主队2-1胜出，则主队赢盘",
                            "showId": "B:",
                            "results": { "女": "A6", "男": "A5" }
                        }, {
                            "showValue": "如果主队1-0胜出，则主队赢盘",
                            "showId": "C:",
                            "results": "A5"
                        }]
                    }, {
                        "id": 9,
                        "problem": "对于越位，下面描述正确的是",
                        "answerItem": [{
                                "showValue": "进攻方传球瞬间，接球球员身后有2名防守队员以上才不算越位",
                                "showId": "A:",
                                "results": "A6"
                            },
                            {
                                "showValue": "如果处在越位位置的球员此次进攻未碰到皮球，均不算越位",
                                "showId": "B:",
                                "results": "A4"
                            }, {
                                "showValue": "角球及界外球均不存在越位",
                                "showId": "C:",
                                "results": "A3"
                            }
                        ]
                    }, {
                        "id": 10,
                        "problem": "关于足球，下面说法正确的是",
                        "answerItem": [{
                            "showValue": "世界杯小组赛比赛中，如果90分钟比分是平局，即将进入点球大战",
                            "showId": "A:",
                            "results": "A2"
                        }, {
                            "showValue": "世界杯决赛比赛中，如果90分钟比分是平局，即将直接i进入点球大战",
                            "showId": "B:",
                            "results": "A2"
                        }, {
                            "showValue": "足球场上每支球队首发10人，其中有1个门将",
                            "showId": "C:",
                            "results": "A1"
                        }, {
                            "showValue": "世界杯获得冠军最多次数的队伍是巴西队",
                            "showId": "D:",
                            "results": "A3"
                        }]
                    }],
                    "bg1": "https://img.alicdn.com/imgextra/i4/20841398/TB2P.LnyKGSBuNjSspbXXciipXa_!!20841398.jpg",
                    "textConfig": {
                        "markPos": [50, 50],
                        "fontSize": 15,
                        "textWidth": 730,
                        "textColor": "#ffffff"
                    },
                    "bg2": "https://img.alicdn.com/imgextra/i4/20841398/TB2kV29yKySBuNjy1zdXXXPxFXa_!!20841398.jpg",
                    "shareTitle": "你也测试一下吧~",
                    "ageConfig": [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],
                    "topicTextBg1": "https://img.alicdn.com/imgextra/i1/20841398/TB2u1EByTlYBeNjSszcXXbwhFXa_!!20841398.png",
                    "topicTextBg2": "https://img.alicdn.com/imgextra/i3/20841398/TB2Vd6GiIj_B1NjSZFHXXaDWpXa_!!20841398.png",
                    "topicsize": "font-size:11pt;color:#fff;",
                    "topicTitleSize": "font-size:28px;color:#fff;",
                    "bgColor1": "#010042",
                    "bgColor2": "#153582",
                    "sexCheckedColor": "#ff6259",
                    "topicResultMessage": "",
                    "topicResultMessNotShow": true,
                    "ZFbtn": "https://img.alicdn.com/imgextra/i3/20841398/TB2jA0YvFOWBuNjy0FiXXXFxVXa_!!20841398.png",
                    "SAVEbtn": "https://img.alicdn.com/imgextra/i4/20841398/TB2Z6lmxCtYBeNjSspaXXaOOFXa_!!20841398.png",
                    "DTbtn": "https://img.alicdn.com/imgextra/i1/20841398/TB21S59vNWYBuNjy1zkXXXGGpXa_!!20841398.png"
                };
            } else if (type == 1) {
                $scope.gift.desc = {
                    "bg1": "https://img.alicdn.com/imgextra/i4/20841398/TB28V98y29TBuNjy1zbXXXpepXa_!!20841398.jpg",
                    "bg2": "https://img.alicdn.com/imgextra/i4/20841398/TB2Dw8qi8smBKNjSZFsXXaXSVXa_!!20841398.jpg",
                    "SAVEwallpaper": ["https://img.alicdn.com/imgextra/i4/20841398/TB2PUHbyY1YBuNjSszeXXablFXa_!!20841398.jpg",
                        "https://img.alicdn.com/imgextra/i4/20841398/TB27zycqOOYBuNjSsD4XXbSkFXa_!!20841398.jpg",
                        "https://img.alicdn.com/imgextra/i4/20841398/TB2dr4jiYZnBKNjSZFGXXbt3FXa_!!20841398.jpg"
                    ],
                    "wallpaper": ["https://img.alicdn.com/imgextra/i4/20841398/TB2PUHbyY1YBuNjSszeXXablFXa_!!20841398.jpg",
                        "https://img.alicdn.com/imgextra/i4/20841398/TB27zycqOOYBuNjSsD4XXbSkFXa_!!20841398.jpg",
                        "https://img.alicdn.com/imgextra/i4/20841398/TB2dr4jiYZnBKNjSZFGXXbt3FXa_!!20841398.jpg"
                    ],
                    "phoneBg": "",
                    "LQLWbtn": "https://img.alicdn.com/imgextra/i2/20841398/TB2TJ9byWSWBuNjSsrbXXa0mVXa_!!20841398.jpg?123",
                    "SAVEIMGbtn": "https://img.alicdn.com/imgextra/i1/20841398/TB28DtOi5QnBKNjSZFmXXcApVXa_!!20841398.png?123",
                    "ZFbtn": "https://img.alicdn.com/imgextra/i1/20841398/TB2pJOkqMKTBuNkSne1XXaJoXXa_!!20841398.png?123",
                    "DTbtn": "",
                    "XCXbtn": "https://img.alicdn.com/imgextra/i2/20841398/TB2sUxUvL9TBuNjy0FcXXbeiFXa_!!20841398.png?123",
                    "titleColor1": "#fdd349",
                    "titleColor2": "#d07efc",
                    "bgColor1": "#fdd349",
                    "bgColor2": "#d07efc"
                }
            }
        }
        $scope.addArray = function(arrayName) {
            if ($scope.gift && $scope.gift.desc) {
                $scope.gift.desc[arrayName].push("");
            }
        }
        $scope.spliceArray = function(arrayName, index) {
            if ($scope.gift && $scope.gift.desc && $scope.gift.desc[arrayName] && $scope.gift.desc[arrayName].length) {
                $scope.gift.desc[arrayName].splice(index, 1);
                console.error("gift", $scope.gift);
            }
        }
        $scope.setCurrentPage = function(name) {
                $scope.setPage = name;
            }
            //tab切换
        $scope.tabCut = function($event) {
            $event.preventDefault();
            $($event.currentTarget).tab('show');
        }
    }
})();